* Draw Nippo graphs *
version 16.1
sysdir set PLUS ado_rdrobust920/plus
cap mkdir ../graph
cap mkdir ../tables

graph drop _all
cap drop thebidder
cap graph drop treatment_s
do "modules/__drawgraph.do"
do "modules/rdbwselect2a.ado"
use ../data/biddata020119.dta, clear
gen firmID = ""
gen mdybid = strofreal(mo_bid) + "/" + strofreal(day_bid) + "/" + strofreal(year_bid) 
gen MDYbid = date(mdybid, "MDY")
rename sc_tech pt_tech
********* Tie auctions (score and price) excluded from RDD ******************
cap drop tie*
foreach k in "s" "p"{
	forvalues z = 1(1)2{
		gen aaa = 1 if ldelta`z'`k'_`k' == 0
		bys id: egen tie`z'`k' = max(aaa)
		drop aaa
	}
	replace tie2`k' = 1 if tie1`k' == 1
}
/* added on 01sep22 to avoid dropping obs in region 4*/
replace pt_tech = . if pt_tech == 0
/* The following 4 lines drop lots of obs in region 4 where there are many obs of pt_tech = 0. We use the same lines when we sent the survey to treatment firms in year 2019; 01sep22 */
bys id: egen min_tech = min(pt_tech)
bys id: egen max_tech = max(pt_tech)
drop if min_tech < 100 & max_tech > 100 /*+100されていないbidderがいる（あ）*/
drop if max_tech > 250 & max_tech < .
gen flag = 1 if pt_tech == 100
cap drop thebidder
gen thebidder = 1 if ustrregexm(nm_firm, "ＮＩＰＰＯ$") == 1 & region == 2 /*& fy_con != 2020*/
tab nm_firm if thebidder == 1
*tab nm_firm if thebidder == 1
local endpd = "31mar2016"
rddelta1x "161952" "2012" "2012" "left" "Before" "small" "td(01apr2012)" "td(31mar2013)" "" "msetwo" "gray"
est store before_s
rddelta1x "161952" "2013" "2015" "right" "After" "small" "td(1apr2013)" "td(`endpd')" "" "msetwo" "gray"
est store after_s
graph combine left right, xsize(6) ysize(4) graphregion(c(white)) /*note("by `endpd'", size(vsmall))*/ ///
	title("NIPPO Corporation", size(medlarge)) scale(1.2) imargin(small) 
graph export "../graph/NIPPO.png", as(png) width(4096) replace

**args ii st_fy en_fy gname gtitle msz st_mdybid ed_mdybid graph
*do "subs/rdbwselect2a.ado"
local endpd = "31mar2016"
rddelta1p "1619" "2012" "2012" "left" "Before" "small" "td(01apr2012)" "td(31mar2013)" "" "msetwo" "grayscale"
est store before_p
rddelta1p "1619" "2013" "2015" "right" "After" "small" "td(1apr2013)" "td(`endpd')" "" "msetwo" "grayscale"
est store after_p
graph combine left right, xsize(6) ysize(4) graphregion(c(white)) /*note("by `endpd'", size(vsmall))*/ ///
	title("NIPPO Corporation", size(medlarge)) scale(1.2) imargin(small)
graph export "../graph/NIPPOp.png", as(png) width(4096) replace

local tval = `e(tau_bc_l)' / `e(se_tau_rb)'


estout before_s after_s using ../tables/nippo0.tex, replace ///
	cells(none) ///
	stats(tau_bc_l se_tau_rb h_l /*b_l *kernel bwselect*/ N_l, fmt(/*%6.0g*/3  3 3 /*3 0 0*/ "%9.0fc",star(tau_bc_l)) ///
		labels(`"\raisebox{0mm}{$\hat{\beta}$}"' `" "' `"\it{h}"' `"Obs."') layout(@ (@) @ @) ) 
	*label varwidth(20) replace style(tex)

	
estout before_p after_p using ../tables/nippo0.tex, append ///
	cells(none) ///
	stats(tau_bc_r se_tau_rb h_r /*b_l *kernel bwselect*/ N_r, fmt(/*%6.0g*/3  3 3 /*3 0 0*/ "%9.0fc",star(tau_bc_l)) ///
		labels(`"\raisebox{0mm}{$\hat{\beta}$}"' `" "' `"\it{h}"' `"Obs."') layout(@ (@) @ @) ) 
	*label varwidth(20) replace style(tex)

